//
//  TheOrderListModel.swift
//  Pods
//
//  Created by eme on 2017/3/28.
//
//

import Foundation
import SwiftyJSON
import ModelProtocol

class TheOrderListModel: ModelProtocol {
    
    // MARK: Declaration for string constants to be used to decode and also serialize.
    internal let kTheOrderListPostageKey: String = "postage"
    internal let kTheOrderListTotalnumberKey: String = "totalnumber"
    internal let kTheOrderListPdnameKey: String = "pdname"
    internal let kTheOrderListOrderidKey: String = "orderid"
    internal let kTheOrderListUnderdateKey: String = "underdate"
    internal let kTheOrderListOrderstatusKey: String = "orderstatus"
    internal let kTheOrderListBdnameKey: String = "bdname"
    internal let kTheOrderListImg1Key: String = "img1"
    internal let kTheOrderListArrayKey: String = "array"
    internal let kTheOrderListOrderamountKey: String = "orderamount"
    internal let kTheOrderListSendtypeKey: String = "sendtype"
    internal let kTheOrderListDetailrnumberKey: String = "detailrnumber"
    internal let kTheOrderListisevaluateKey: String = "isevaluate"
    internal let kTheOrderListpaycouponidKey: String = "paycouponid"
    internal let kTheOrderListpayidKey: String = "payid"
    internal let kTheOrderListpaycouponkey:String = "paycoupon"
    internal let kTheOrderListpayarraykey:String = "payarray"
    internal let kTheOrderListbdpricekey:String = "bdpricetotal"
    
    
    // MARK: 属性
    var postage: Double
    var totalnumber: Int
    var pdname: String
    var orderid: String
    var underdate: String
    var orderstatus: String
    var bdname: String
    var img1: String
    var array: [ArrayModel]
    var orderamount: Double
    var sendtype: String
    var detailrnumber: Int
    var isevaluate:String
    var paycouponid:String
    var payid:String
    var paycoupon:Double
    var payarray:[PayArrayModel]
    var bdprice:Double
    
    
    
    // MARK: 实现MikerSwiftJSONAble 协议， 解析json数据
    required  init?(json: JSON) {
        postage = json[kTheOrderListPostageKey].doubleValue
        totalnumber = json[kTheOrderListTotalnumberKey].intValue
        pdname = json[kTheOrderListPdnameKey].stringValue
        orderid = json[kTheOrderListOrderidKey].stringValue
        underdate = json[kTheOrderListUnderdateKey].stringValue
        orderstatus = json[kTheOrderListOrderstatusKey].stringValue
        bdname = json[kTheOrderListBdnameKey].stringValue
        img1 = json[kTheOrderListImg1Key].stringValue
        array = []
        if let items = json[kTheOrderListArrayKey].array {
            for item in items {
                if let arrayModel = ArrayModel(json: item){
                    array.append(arrayModel)
                }
            }
        } else {
            array = []
        }
        orderamount = json[kTheOrderListOrderamountKey].doubleValue
        sendtype = json[kTheOrderListSendtypeKey].stringValue
        detailrnumber = json[kTheOrderListDetailrnumberKey].intValue
        isevaluate = json[kTheOrderListisevaluateKey].stringValue
        paycouponid = json[kTheOrderListpaycouponidKey].stringValue
        payid = json[kTheOrderListpayidKey].stringValue
        paycoupon = json[kTheOrderListpaycouponkey].doubleValue
        bdprice = json[kTheOrderListbdpricekey].doubleValue
        payarray = []
        if let items = json[kTheOrderListpayarraykey].array {
            for item in items {
                if let arrayModel = PayArrayModel(json: item){
                    payarray.append(arrayModel)
                }
            }
        } else {
            payarray = []
        }
        
    }
    
    
    /**
     Generates description of the object in the form of a NSDictionary.
     - returns: A Key value pair containing all valid values in the object.
     */
    internal func dictionaryRepresentation() -> [String : AnyObject ] {
        
        var dictionary: [String : AnyObject ] = [ : ]
        
        dictionary.updateValue(postage as AnyObject, forKey: kTheOrderListPostageKey)
    
    
        dictionary.updateValue(totalnumber as AnyObject, forKey: kTheOrderListTotalnumberKey)
    
    
        dictionary.updateValue(pdname as AnyObject, forKey: kTheOrderListPdnameKey)
    
        dictionary.updateValue(orderid as AnyObject, forKey: kTheOrderListOrderidKey)
    
        dictionary.updateValue(underdate as AnyObject, forKey: kTheOrderListUnderdateKey)
    
        dictionary.updateValue(orderstatus as AnyObject, forKey: kTheOrderListOrderstatusKey)
    
        dictionary.updateValue(bdname as AnyObject, forKey: kTheOrderListBdnameKey)
    
        dictionary.updateValue(img1 as AnyObject, forKey: kTheOrderListImg1Key)
        
        if array.count > 0 {
            var temp: [AnyObject] = []
            for item in array {
                temp.append(item.dictionaryRepresentation() as AnyObject)
            }
            dictionary.updateValue(temp as AnyObject, forKey: kTheOrderListArrayKey)
        }
        
        dictionary.updateValue(orderamount as AnyObject, forKey: kTheOrderListOrderamountKey)
    
        dictionary.updateValue(sendtype as AnyObject, forKey: kTheOrderListSendtypeKey)
    
        dictionary.updateValue(detailrnumber as AnyObject, forKey: kTheOrderListDetailrnumberKey)
    
        dictionary.updateValue(isevaluate as AnyObject, forKey: kTheOrderListisevaluateKey)
    
        dictionary.updateValue(paycouponid as AnyObject, forKey: kTheOrderListpaycouponidKey)
    
        dictionary.updateValue(payid as AnyObject, forKey: kTheOrderListpayidKey)
    
        dictionary.updateValue(paycoupon as AnyObject, forKey: kTheOrderListpaycouponkey)
        
        if payarray.count > 0 {
            var temp: [AnyObject] = []
            for item in payarray {
                temp.append(item.dictionaryRepresentation() as AnyObject)
            }
            dictionary.updateValue(temp as AnyObject, forKey: kTheOrderListpayarraykey)
        }
        dictionary.updateValue(bdprice as AnyObject, forKey: kTheOrderListbdpricekey)
        return dictionary
    }
}
